//
//  MainTabbarViewController.m
//  Haliaeetus
//
//  Created by junli hou on 2018/3/20.
//  Copyright © 2018年 BMY. All rights reserved.
//

#import "MainTabbarViewController.h"
#import "HomeViewController.h"
#import "TravelListViewController.h"
#import "MeViewController.h"
#import "BaseNavigationController.h"
#import "WebViewManager.h"
@interface MainTabbarViewController ()

@end

@implementation MainTabbarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initWithControllers];
}

- (void)initWithControllers {
    HomeViewController *homeController = [[HomeViewController alloc] init];
    BaseNavigationController *homeNavigationController = [[BaseNavigationController alloc] initWithRootViewController:homeController];
    homeController.tabBarItem = [self setupTabBarItemWithImageName:@"home" selectedImageName:@"home_sel" title:@"酒店预定"  tag:0];
    [[WebViewManager defaultManager] setMainNavigationController:homeNavigationController];
    
    TravelListViewController *travelListViewController = [[TravelListViewController alloc] init];
    BaseNavigationController *travelListNavigationController = [[BaseNavigationController alloc] initWithRootViewController:travelListViewController];
        travelListViewController.tabBarItem = [self setupTabBarItemWithImageName:@"trl" selectedImageName:@"trl_sel" title:@"行程"  tag:1];
    
    MeViewController *meController = [[MeViewController alloc] init];
    BaseNavigationController *meNavigationController = [[BaseNavigationController alloc] initWithRootViewController:meController];
    meController.tabBarItem = [self setupTabBarItemWithImageName:@"me" selectedImageName:@"me_sel" title:@"我的"  tag:2];
    
    
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:WS_RGB(51, 51, 51), UITextAttributeTextColor, nil] forState:UIControlStateNormal];
    [[UITabBarItem appearance] setTitleTextAttributes:                                                         [NSDictionary dictionaryWithObjectsAndKeys:WS_RGB(255, 115, 0),UITextAttributeTextColor, nil]forState:UIControlStateSelected];
    
    self.viewControllers = @[homeNavigationController,travelListNavigationController,meNavigationController];
    
}

- (UITabBarItem *)setupTabBarItemWithImageName:(NSString *)imageName selectedImageName:(NSString *)selectedImageName title:(NSString*)title tag:(NSInteger)tag {
    UITabBarItem *tabBarItem;
    tabBarItem = [[UITabBarItem alloc] initWithTitle:nil
                                               image:[[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
                                       selectedImage:[[UIImage imageNamed:selectedImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    tabBarItem.title=title;
    tabBarItem.tag = tag;
    return tabBarItem;
}

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
    [[WebViewManager defaultManager] setMainNavigationController:[self.viewControllers objectAtIndex:item.tag]];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
